{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0",
   "metadata": {},
   "source": [
    "# Getting started with Reachy 2"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1",
   "metadata": {},
   "source": [
    "In this first tutorial, we will familiarize ourselves with Reachy. We will cover how to connect to the robot and obtain basic information."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2",
   "metadata": {},
   "source": [
    "## Connect to Reachy"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3",
   "metadata": {},
   "source": [
    "First, establish a connection to your robot:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4",
   "metadata": {},
   "outputs": [],
   "source": [
    "from reachy2_sdk import ReachySDK\n",
    "\n",
    "reachy = ReachySDK(host='localhost')  # Replace localhost with your robot's IP address"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5",
   "metadata": {},
   "source": [
    "You can check the connection status at any time with:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6",
   "metadata": {},
   "outputs": [],
   "source": [
    "reachy.is_connected()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7",
   "metadata": {},
   "source": [
    "Reachy is now ready for use. By default, all motors are turned off. In the next tutorial, we will learn how to move Reachy. The overall status of Reachy's motors can be checked as follows:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8",
   "metadata": {},
   "outputs": [],
   "source": [
    "reachy.is_on() # will return False because the motors are off by default"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9",
   "metadata": {},
   "source": [
    "Let's retrieve information about the robot, including mode, serial number, hardware / software versions, and battery level:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "10",
   "metadata": {},
   "outputs": [],
   "source": [
    "reachy.info"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "11",
   "metadata": {},
   "source": [
    "You can also access these informations independently, for example:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "12",
   "metadata": {},
   "outputs": [],
   "source": [
    "reachy.info.battery_voltage"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "13",
   "metadata": {},
   "source": [
    "## Body parts"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "14",
   "metadata": {},
   "source": [
    "Let's take a look at Reachy's body. Reachy's arm has 7 degrees of freedom and one joint for the gripper.\n",
    "\n",
    "The **arm** is divided into the following elements:\n",
    "- **shoulder**, consisting of 2 joints (pitch and roll)\n",
    "- **elbow**, consisting of 2 joints (yaw and pitch)\n",
    "- **wrist**, consisting of 3 joints (roll, pitch, and yaw)\n",
    "- **gripper**, consisting by default of 1 joint accessed directly at the gripper level\n",
    "\n",
    "We refer to the shoulder, elbow, and wrist as **actuators**. A joint is essentially an axis along which the actuator can rotate.\n",
    "For some actions, such as changing the compliancy, this is the lowest level of control you will have.\n",
    "The default parallel gripper is a specific actuator that has only one joint, so everything is accessed at its level.\n",
    "\n",
    "The head consists of three actuators: the **neck**, with 3 degrees of freedom (joints), and **l_antenna** and **r_antenna**, with a single joint for each of them.\n",
    "\n",
    "The following command lists all available joints:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "15",
   "metadata": {},
   "outputs": [],
   "source": [
    "reachy.joints"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "16",
   "metadata": {},
   "source": [
    "The current and goal positions are also listed (i.e., the present and target angles of the joints).\n",
    "Each body part can be explored individually:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "17",
   "metadata": {},
   "outputs": [],
   "source": [
    "reachy.r_arm.joints\n",
    "#reachy.l_arm.joints\n",
    "#reachy.head.joints"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "18",
   "metadata": {},
   "source": [
    "## Mobile Base"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "19",
   "metadata": {},
   "source": [
    "The mobile base can be accessed in the same way as the body parts:\n",
    "> Be aware that there is no mobile base in the fake mode configuration. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "20",
   "metadata": {},
   "outputs": [],
   "source": [
    "reachy.mobile_base"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "21",
   "metadata": {},
   "source": [
    "## Disconnect"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "22",
   "metadata": {},
   "source": [
    "No action is required; simply close your terminal or notebook!\n",
    "\n",
    "If you need to switch between robots, you can disconnect from one and then connect to another:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "23",
   "metadata": {},
   "outputs": [],
   "source": [
    "reachy.disconnect()\n",
    "\n",
    "reachy = ReachySDK(host='localhost') # connect to a new robot with its IP address"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
